package name.jiaosha.air.repair.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import name.jiaosha.air.AppConstants;
import name.jiaosha.air.repair.domain.Repair;
import name.jiaosha.air.repair.domain.RepairItem;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ali8ba.common.AliUtil;

/**
 * 维修单控制器
 * 
 * @author xu
 * 
 */
@Controller
@RequestMapping("/admin")
public class RepairController {

	@RequestMapping("/repair/findList")
	public ModelAndView getRepairist() {

		List<Repair> list = null;

		if (AppConstants.DEBUG) {
			list = new ArrayList<Repair>();
			for (int i = 1000; i < 1020; i++) {
				Repair repair = new Repair();
				repair.setDocID("20100912" + i);
				repair.setBuyer("张先生" + Math.random());
				repair.setPhone("1882566002");
				repair.setMobile("8848520");
				repair.setAddress("杭州天堂软件园");
				repair.setRemarks("备注" + i);
				repair.setCreateMan("黄光裕");
				repair.setBuyDate(AliUtil.getDaysAfter(-3));
				// install.setDeliverDate(AliUtil.getDaysAfter(-2));
				repair.setFixDate(new Date());
				if (i == 1002) {
					repair.setFixDate(AliUtil.getDaysAfter(-2));
				}
				if (i > 1010) {
					repair.setFixDate(AliUtil.getDaysAfter(1));
				}
				list.add(repair);
			}

		} else {

		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", list);
		return new ModelAndView("jsonView", model);
	}

	@RequestMapping("/repair/repairInfo")
	public ModelAndView repairInfo() {

		Repair reapir = null;
		List<RepairItem> list = null;
		if (AppConstants.DEBUG) {

			reapir = new Repair();
			reapir.setDocID("20100803001");
			reapir.setFixDate(new Date());
			reapir.setAddress("杭州天堂");
			reapir.setPhone("05718568");
			reapir.setMobile("137774363");
			reapir.setRemarks("要求上午安装");
			list = new ArrayList<RepairItem>();
			for (int i = 0; i < 3; i++) {
				RepairItem repairItem = new RepairItem();
				repairItem.setAmount(i + 1);
				repairItem.setInbarcode("3026666555");
				repairItem.setOutbarcode("9556626655");
				repairItem.setTypeCode("KFR-50LW/DY-S2");
				repairItem.setBugDesc("不制冷，效果不好");
				list.add(repairItem);

			}

		} else {

		}

		ModelMap model = new ModelMap();
		model.addAttribute("root", reapir);
		model.addAttribute("item",list);
		return new ModelAndView("jsonView", model);
	}

}
